/**
 * 
 */
package Consult.view;

import java.awt.EventQueue;
import java.sql.ResultSet;
import java.util.Vector;

import javax.swing.JInternalFrame;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

import com.mysql.jdbc.Connection;


import Consult.model.BookType;
import Util.DBUtils;

/**
 * @author zhaoyana
 *
 */
public class BookTypeManageInterFrm extends JInternalFrame {
	private JTable bookTableTable;
	private DBUtils dbUtil=new DBUtils();
	private BookTypeDao bookTypeDao=new BookTypeDao();

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					BookTypeManageInterFrm frame = new BookTypeManageInterFrm();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public BookTypeManageInterFrm() {
		setClosable(true);
	
		setMaximizable(true);
		setIconifiable(true);
		setResizable(true);
		setTitle("鍥句功绫诲埆绠＄悊\r\n");
		setBounds(100, 100, 735, 610);
		
		JScrollPane scrollPane = new JScrollPane();
		GroupLayout groupLayout = new GroupLayout(getContentPane());
		groupLayout.setHorizontalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(Alignment.TRAILING, groupLayout.createSequentialGroup()
					.addContainerGap(114, Short.MAX_VALUE)
					.addComponent(scrollPane, GroupLayout.PREFERRED_SIZE, 492, GroupLayout.PREFERRED_SIZE)
					.addGap(113))
		);
		groupLayout.setVerticalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(Alignment.TRAILING, groupLayout.createSequentialGroup()
					.addContainerGap(134, Short.MAX_VALUE)
					.addComponent(scrollPane, GroupLayout.PREFERRED_SIZE, 380, GroupLayout.PREFERRED_SIZE)
					.addGap(64))
		);
		
		bookTableTable = new JTable();
		bookTableTable.setModel(new DefaultTableModel(
			new Object[][] {
			},
			new String[] {
				"\u7F16\u53F7", "\u56FE\u4E66\u7C7B\u522B", "\u56FE\u4E66\u7C7B\u522B\u63CF\u8FF0"
			}
		) {
			boolean[] columnEditables = new boolean[] {
				true, false, true
			};
			public boolean isCellEditable(int row, int column) {
				return columnEditables[column];
			}
		});
		scrollPane.setViewportView(bookTableTable);
		getContentPane().setLayout(groupLayout);
		this.fillTable(new BookType());

	}
	//鍒濆鍖栬〃鏍�
	private void fillTable(BookType bookType) {
		DefaultTableModel dtm=(DefaultTableModel) bookTableTable.getModel();
	  dtm.setRowCount(0);//娓呯┖琛ㄦ牸
	  Connection con=null;
	  try {
		  con=(Connection) dbUtil.getCon();
		 ResultSet rs= bookTypeDao.list(con, bookType);
		 //閬嶅巻
		  while(rs.next()) {
			  Vector v=new Vector();
			  v.add(rs.getString("id"));
			  v.add(rs.getString("bookTypeName"));
			  v.add(rs.getString("bookTypeDesc"));
			  dtm.addRow(v);
		  }
	  }catch(Exception e) {
		  e.printStackTrace();;
	  }finally {
		  try {
			dbUtil.closeCon(con);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	  }
	}
}
